﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using NovinMedia.Data;

namespace NovinMedia.Data.Layer
{
    [DataObject(true)]
    public class KhachHang
    {
		[DataObjectMethod(DataObjectMethodType.Fill)]
		public DataSet SelectAll()
        {
            DbObject dbo = new DbObject();
            SqlParameter[] parameters = new SqlParameter[]
                {
 
                };
            return dbo.RunProcedure("pr_KhachHang_SelectAll", parameters, "KhachHang");
        }

		[DataObjectMethod(DataObjectMethodType.Fill)]
		public DataSet SelectRow(string MaKH)
        {
            DbObject dbo = new DbObject();
            SqlParameter[] parameters = new SqlParameter[]
                {
					new SqlParameter("MaKH",MaKH) 
                };
            return dbo.RunProcedure("pr_KhachHang_SelectRow", parameters, "KhachHang");
        }

		[DataObjectMethod(DataObjectMethodType.Insert)]
		public int InsertRow(string MaKH,string TenKH,string DiaChi,string SDT)
		{
			int RowsAffected = 0;
			int Result = 0;
			DbObject dbo = new DbObject();
			SqlParameter[] parameters = new SqlParameter[]
				{
					new SqlParameter("MaKH",MaKH),
					new SqlParameter("TenKH",TenKH),
					new SqlParameter("DiaChi",DiaChi),
					new SqlParameter("SDT",SDT) 
				};
			Result = dbo.RunProcedure("pr_KhachHang_Insert", parameters, out RowsAffected);
			return Result;
        }

		[DataObjectMethod(DataObjectMethodType.Update)]
		public int UpdateRow(string MaKH,string TenKH,string DiaChi,string SDT)
		{
			int RowsAffected = 0;
			int Result = 0;
			DbObject dbo = new DbObject();
			SqlParameter[] parameters = new SqlParameter[]
				{
					new SqlParameter("MaKH",MaKH),
					new SqlParameter("TenKH",TenKH),
					new SqlParameter("DiaChi",DiaChi),
					new SqlParameter("SDT",SDT) 
				};
			Result = dbo.RunProcedure("pr_KhachHang_Update", parameters, out RowsAffected);
			return Result;
        }

		[DataObjectMethod(DataObjectMethodType.Delete)]
		public int DeleteRow(string MaKH)
		{
			int RowsAffected = 0;
			int Result = 0;
			DbObject dbo = new DbObject();
			SqlParameter[] parameters = new SqlParameter[]
				{
					new SqlParameter("MaKH",MaKH) 
				};
			Result = dbo.RunProcedure("pr_KhachHang_DeleteRow", parameters, out RowsAffected);
			return Result;
        }
    }
}